package com.zc;

import com.zc.config.SmsConfig;
import com.zc.custom.CustomEvent;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@SpringBootApplication()
// 配置属性扫描注解,如果配置属性类在同一个文件夹下,这种方式会方便点
@ConfigurationPropertiesScan("com.zc.property")

// 开启aop
@EnableAspectJAutoProxy
@MapperScan("com.zc.dao")
public class Springboot3HelloApplication {

    public static void main(String[] args) {
        System.out.println("传入的参数" + Arrays.toString(args));
        SpringApplication springApplication = new SpringApplication(Springboot3HelloApplication.class);

        // 添加额外的配置文件,对应配置文件属性spring.profiles.include
//        springApplication.setAdditionalProfiles("");

        // 设置自定义有banner
//        springApplication.setBanner(new CustomBanner());

        // 设置banner打印模式 OFF-不打印banner  也可在配置文件中进行配置
//        springApplication.setBannerMode(Banner.Mode.OFF);
        ConfigurableApplicationContext context = springApplication.run(args);
        System.out.println("发布CustomEvent");
        context.publishEvent(new CustomEvent(springApplication));

        SmsConfig config = context.getBean(SmsConfig.class);
        config.smsService().send("123456789", "hello world");
    }



}

@Component
class MyApplicationRunner implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("MyApplicationRunner:" +args);
    }
}
